#!/bin/env python
#-*-coding:utf-8-*-   


from database import Connection
from x_date    import    Date
import datetime



class Io_base():
    def __init__(self,host, database, user=None, password=None):
        '''sample:  
        db = Connection("10.36.15.40:3306","CL_netdisk","chunlei","chunlei")
            for files in db.iter("select * from share_files"):
            print files
            data = (u"我的文件",1,78,u"庄",1,"hao123")
            print db.execute_rowcount("insert into share_files(filename,isdir,uid,username,property,shareid) values(%s,%s,%s,%s,%s,%s);",*data)
        '''
        self.db = Connection(host, database, user, password)
        self.date = Date()
        pass


    def caculate_timestamp(self,str_today):
        self.today = self.date.strtodatetime(str_today,"%Y-%m-%d")
        self.yesterday =  self.today - datetime.timedelta(days=1)       
        self.today_timestamp = self.date.datetime2timestamp(self.today)
        self.yesterday_timestamp = self.date.datetime2timestamp(self.yesterday)


    def output2file(self,valid_dict,filename):
        f = open(filename,"a")
        for item in valid_dict:
            print >>f,item,"\t",valid_dict[item]
        f.close()
        

    def list2dict(self,imei_list,suffix):
        tmp_dict = {}
        for item in imei_list:
            tmp_dict[item[0]+suffix] = item[1] 
        return tmp_dict
        


def main():



    pass




if __name__ == "__main__":
    main()

# vim: et
